package com.leave.service;

import com.leave.dao.StudentDao;
import com.leave.entity.Course;
import com.leave.entity.Student;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * 用户管理Service类， 封装表示业务逻辑处理的成员方法
 * @author amu_1115@126.com
 */
public class StudentService {
    private StudentDao userDao;

    /**
     * 验证用户合法性
     * @param stuID
     * @param password
     * @return
     */
     public boolean checkStudent(String stuID,String password){
         boolean flag = false;
         Student stu = new Student();
         stu.setStuID(stuID);
         stu.setPassword(password);
         List<Student> list = userDao.query(stu);
         flag =!list.isEmpty();
         return flag;
     }

    /**
     * 查找userid对应的记录
     * @param stuID
     * @return
     */
     public List<Student> findStudent(String stuID){
       Student stu =new Student();
       stu.setStuID(stuID);
       List<Student> list =userDao.query(stu);
       if(!list.isEmpty()){
           return  list;
       }else{
           return null;
       }
     }

     /**
      *
      *模糊查找
      */
     public List<Map<String, Object>> seekStudent(String keyword) throws SQLException {
         if(keyword != null){
             return userDao.selectStuList(keyword);
         }else{
             return null;
         }
     }

    /**
     * 模糊查找所有记录
     * @param example
     * @return
     */
     public List<Student> listStudent(Student example){
         List<Student> list =null;
         list = userDao.query(example);
         return list;
     }

    /**
     * 添加用户
     * @param user
     */
     public boolean addStudent(Student user){
         userDao.insert(user);
         return true;
     }

    /**
     *
     * @param user
     */
    public boolean editStudent(Student user){
          userDao.update(user);
          return true;
    }

    /**
     * 删除用户
     * @param userid
     *
     */
    public boolean deleteStudent(String userid){
        userDao.delete(userid);
        return true;
    }


    public void setStudentDao(StudentDao studentDao) {
        this.userDao = studentDao;
    }
}
